/**
 * 
 */
package com.orisper.omp.modules.cata;

import java.util.Date;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.orisper.dao.Bm_cataDao;
import com.orisper.dao.Bm_cataPO;

import aos.framework.core.typewrap.Dto;
import aos.framework.core.utils.AOSJson;
import aos.framework.web.router.HttpModel;
import aos.system.common.service.AOSBaseService;

/**
 * @author dl
 *
 */
@Service
public class CataService extends AOSBaseService{
	
	@Autowired
	Bm_cataDao bm_cataDao;
	
	
	/**
	 * 分类管理页面初始化
	 * 
	 * @param httpModel
	 * @return
	 */
	public void init(HttpModel httpModel) {
		httpModel.setAttribute("juid", httpModel.getInDto().getString("juid"));
		httpModel.setViewPath("project/orisper/cataManage.jsp");
	}

	
	/**
	 * 查询分类管理列表
	 * 
	 * @param httpModel
	 */
	public void cataList(HttpModel httpModel) {
		Dto inDto = httpModel.getInDto();
		List<Dto> list = sqlDao.list("Cata.cataListPage",inDto);
		httpModel.setOutMsg(AOSJson.toGridJson(list, inDto.getPageTotal()));
	}

	
	/**
	 * 查询分类信息
	 * 
	 * @param httpModel
	 */
	public void getCata(HttpModel httpModel) {
		Dto inDto = httpModel.getInDto();
		Bm_cataPO bm_cataPO = bm_cataDao.selectByKey(inDto.getInteger("id"));
		httpModel.setOutMsg(AOSJson.toJson(bm_cataPO));
	}
	
	/**
	 * 修改分类信息
	 * 
	 * @param httpModel
	 */
	public void updateCata(HttpModel httpModel) {
		Dto inDto = httpModel.getInDto();
		Bm_cataPO bm_cataPO = new Bm_cataPO();
		bm_cataPO.copyProperties(inDto);
		bm_cataPO.setModify_date(new Date());
		bm_cataDao.updateByKey(bm_cataPO);
		httpModel.setOutMsg("修改成功");
	}
	
	/**
	 * 添加分类
	 * @param httpModel
	 */
	public void addCata(HttpModel httpModel) {
		Dto inDto = httpModel.getInDto();
		Bm_cataPO bm_cataPO = new Bm_cataPO();
		bm_cataPO.copyProperties(inDto);
		bm_cataPO.setCreate_date(new Date());
		bm_cataDao.insert(bm_cataPO);
		httpModel.setOutMsg("添加成功");
	}
	

	/**
	 * 删除
	 * 
	 * @param httpModel
	 * @return
	 */
	public void deleteCata(HttpModel httpModel) {
		Dto inDto = httpModel.getInDto();
		Integer res=bm_cataDao.deleteByKey(inDto.getInteger("id"));
		String result=res>0?"删除成功":"删除失败";
		httpModel.setOutMsg(result);
	}
}
